
package com.wyzz.hr.action;

import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.bo.UserBo;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Userinfo;

public class DeleteRecord extends BaseAction {

	public DeleteRecord() {
	}

	public String delEmp() throws Exception {
		if (StringUtils.isEmpty(id))
			return "success";
		if (getCurrentEmpNo().equalsIgnoreCase(id)) {
			addErrorInfo("\u4E0D\u80FD\u5220\u9664\u672C\u4EBA\u7684\u57FA\u672C\u8D44\u6599\uFF01");
			return "success";
		}
		IEmployeeBo empBo = (IEmployeeBo) getBean("empBo");
		Employee delEmp = empBo.loadEmp(id, null);
		if (delEmp == null)
			return "success";
		UserBo userBo = (UserBo) getBean("userService");
		Userinfo oldUserinfo = userBo.getUserById(id);
		if (userBo.checkAuthModule(oldUserinfo, "911")) {
			addErrorInfo("\u5220\u9664\u5931\u8D25\uFF0C\u6B64\u7528\u6237\u4E3A\u7CFB\u7EDF\u7BA1\u7406\u5458\uFF0C\u8BF7\u5230\u7CFB\u7EDF\u6A21\u5757\u53D6\u6D88\u6B21\u7528\u6237\u7684\u7BA1\u7406\u5458\u6743\u9650\u540E\u5220\u9664\uFF01");
			return "success";
		}
		List errors = null;
		String empName = delEmp.getEmpName();
		try {
			errors = empBo.deleteEmp(delEmp);
		} catch (Exception e) {
			e.printStackTrace();
			addErrorInfo("\u5220\u9664\u5458\u5DE5\u57FA\u672C\u8D44\u6599\u5931\u8D25\uFF01");
			return "success";
		}
		if (errors != null && errors.size() > 0)
			addErrorInfo(errors);
		else
			addSuccessInfo((new StringBuilder())
					.append(empName)
					.append(
							"\u7684\u57FA\u672C\u8D44\u6599\u5DF2\u88AB\u5220\u9664\u3002")
					.toString());
		return "success";
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	private static final long serialVersionUID = 0xc53a77b0ae03eebfL;
	private static final String AUTHMODULE = "911";
	private String id;
	private static final Logger logger = Logger
			.getLogger(com.wyzz.hr.action.DeleteRecord.class);

}
